package per.ethan.javase.thread;

/**
 * @author Ethan
 * @date 2020/04/27 10:20
 */
public class Demo1 extends Thread {

    private boolean flag = true;

    public static void main(String[] args) {
        Demo1 demo1 = new Demo1();
        demo1.start();
        for (int i = 0; i < 20; i++) {
            System.out.println("main: " + i);
            if (i == 15) {
                demo1.threadStop();
            }
        }
    }

    @Override
    public void run() {
        int i = 0;
        while (flag) {
            System.out.println("thread：" + i++);
        }

    }

    private void threadStop() {
        flag = false;
    }

}
